<?php include(ADMIN_ROOT.'template/header.tpl.php');?>
<div class="box">
 	<div class="heading">
		<h1>静态生成</h1>
	</div>
	<div class="main">
	<div class="tab">
			<ul>
				<li><a href="admin.php?m=plugin&f=inlist" >已安装</a></li>
				<li><a href="admin.php?m=plugin&f=unlist" >未安装</a></li>
			</ul>
		</div>
	<?php if ( $f == 'inlist' || $f == 'unlist' ) : ?>
		<fieldset>
			<legend>安装说明：</legend>
			请将插件上传至 plugins 目录，然后到“未安装”列表中进行安装。
		</fieldset>
	<?php endif; ?>

	<?php if ( $f == 'inlist' ) : ?>
		<table cellspacing="0" class="datalist" id="list">
			<tr>
				<th width="120" class="firstcol">插件名称</th>
				<th width="120">唯一标识</th>
				<th width="120">所在目录</th>
				<th width="100">作者</th>
				<th width="80">版本</th>
				<th>作者主页</th>
				<th width="80">运行模式</th>
				<th width="80">状态</th>
				<th width="60">操作</th>
			</tr>

			<?php
			if (empty($result)) {
				echo '<tr><td colspan="9">目前尚未安装任何插件...</td></tr>';		
			} else {
				foreach ( $result as $row ) {
			?>
			<tr align="center">
				<td>
				<?php
				$adminfile = BASE_ROOT.'plugins/'.$row['directory'].'/admin.php';
				if ( file_exists($adminfile) ) {
					echo '<a href="?m=plugin_admin&p='.rawurlencode($row['identifier']).'" title="点击进入管理插件">'.$row['name'].'</a>';
				} else { echo $row['name']; }
				?>
				</td>
				<td><?php echo $row['identifier']; ?></td>
				<td><?php echo $row['directory']; ?></td>
				<td><?php echo $row['author']; ?></td>
				<td><?php echo $row['version']; ?></td>
				<td><?php if (!empty($row['homepage'])) {echo '<a href="'.$row['homepage'].'" target="_blank" title="访问作者主页">'.$row['homepage'].'</a>';} ?></td>
				<td><?php echo plugin_runmode($row['runmode']);?></td>
				<td><?php echo $row['enabled'] ? '<a href="?m=plugin&f=enabled&val=0&pid='.$row['id'].'" title="使用中，点击停用该插件"><img src="admin/template/images/start.gif" /></a>':'<a href="?m=plugin&f=enabled&val=1&pid='.$row['id'].'" title="已停用，点击启用该插件"><img src="admin/template/images/stop.gif" /></a>';?></td>
				<td><a href="?m=plugin&f=uninstall&pid=<?php echo $row['id'];?>" onclick="return confirm('卸载插件将会删除所有插件相关数据，并且不可恢复，确定要卸载吗？')">卸载</a></td>
			</tr>
			<?php 
				}
			}
			?>
		</table>
	<?php elseif ( $f == 'unlist' ) : ?>

		<table cellspacing="0" class="datalist" id="list">
			<tr>
				<th width="150" class="firstcol">插件名称</th>
				<th width="150">所在目录</th>
				<th width="150">作者</th>
				<th width="80">版本</th>
				<th>作者主页</th>
				<th width="80">运行模式</th>
				<th width="60">操作</th>
			</tr>

			<?php
			if (empty($result)) {
				echo '<tr><td colspan="9">没有未安装的插件...</td></tr>';		
			} else {
				foreach ( $result as $row ) {
			?>
			<tr align="center">
				<td><?php echo $row['name']; ?></td>
				<td><?php echo $row['directory']; ?></td>
				<td><?php echo $row['author']; ?></td>
				<td><?php echo $row['version']; ?></td>
				<td><?php if (!empty($row['homepage'])) {echo '<a href="'.$row['homepage'].'" target="_blank" title="访问作者主页">'.$row['homepage'].'</a>';} ?></td>
				<td><?php echo plugin_runmode($row['runmode']);?></td>
				<td><a href="<?php echo $row['installurl'];?>" title="安装该插件">安装</a></td>
			</tr>
			<?php 
				}
			}
			?>
		</table>

	<?php elseif ( $f == 'install' ) : ?>
		
	<form name="install" method="post" action="?m=plugin&f=install" />
	<input type="hidden" name="dosubmit" value="yes" />
	<input type="hidden" name="directory" value="<?php echo $plugininfo['directory']?>" />
		<table>
			<tr><th colspan="2">请确认插件信息：</th></tr>
			<tr>
				<td align="right">插件名称：</td>
				<td><input type="text" name="name" size="20" value="<?php echo $plugininfo['name'];?>" /></td>
			</tr>
			<tr>
				<td align="right">唯一标识：</td>
				<td><input type="text" name="identifier" size="20" value="<?php echo $plugininfo['directory'];?>" /><span>系统通过该名称访问插件，不可与其他插件重复</span></td>
			</tr>
			<tr>
				<td align="right">插件目录：</td>
				<td><?php echo 'plugins/'.$plugininfo['directory'].'/';?></td>
			</tr>
			<tr>
				<td align="right">运行模式：</td>
				<td><?php echo plugin_runmode($plugininfo['runmode']);?></td>
			</tr>
			<tr>
				<td align="right">插件作者：</td>
				<td><?php echo $plugininfo['author'];?></td>
			</tr>
			<tr>
				<td align="right">插件版本：</td>
				<td><?php echo $plugininfo['version'];?></td>
			</tr>
			<tr>
				<td align="right">作者主页：</td>
				<td><?php echo $plugininfo['homepage'];?></td>
			</tr>
			<tr>
				<td></td>
				<td><input type="submit" class="button" value="开始安装" /> <input type="button" class="button" value="取消返回" onclick="javascript:history.back();" /></td>
			</tr>
		</table>
	</form>

	<?php endif;?>

<?php include(ADMIN_ROOT.'template/footer.tpl.php');?>